<script src="/include/calendar/calendar.js"></script>
<style type="text/css">
a {
	cursor: pointer;
}
#search-form input,#search-form select {
	width: 116px;
}
#search-form .form-group {
	margin-right: 5px;
}
</style>
<div class="pageheader">
	<h2>
		<i class="fa fa-pencil-square"></i>日志管理
	</h2>
	<div class="breadcrumb-wrapper">
		<span class="label">你所在的位置：</span>
		<ol class="breadcrumb">
			<li><a href="/index">ERP管理系统</a></li>
			<li>日志管理</li>
			<li class="active">网站订单日志</li>
		</ol>
	</div>
</div>
<div class="contentpanel">
<div class="main">
    <form id="search-form" class="form-inline" method="post" action="/log/order" style="margin-bottom: 10px;">
        <div class="form-group">
            <!-- <label for="Orderid">订单号</label> -->
            <input type="text" name="orderid" value="<?php echo $this->orderid;?>" class="form-control" placeholder="订单号">
        </div>
        <div class="form-group">
            <!-- <label for="SKU">SKU</label> -->
            <input type="text" name="sku" value="<?php echo $this->sku;?>" class="form-control" placeholder="SKU">
        </div>
        <div class="form-group">
            <!--<label for="Site">网站</label> -->
            <select class='form-control' name='site'>
                <option value='' <?php if($this->site == ''){echo 'selected="selected"';}?>>选择网站</option>
                <option value='gogoalshop.com' <?php if($this->site == 'gogoalshop.com'){echo 'selected="selected"';}?>>gogoalshop.com</option>
		        <option value='minejerseys.com' <?php if($this->site == 'minejerseys.com'){echo 'selected="selected"';}?>>minejerseys.com</option>
		        <option value='jerseysmark.com' <?php if($this->site == 'jerseysmark.com'){echo 'selected="selected"';}?>>jerseysmark.com</option>
		        <option value='goaljerseys.com' <?php if($this->site == 'goaljerseys.com'){echo 'selected="selected"';}?>>goaljerseys.com</option>
		        <option value='fancybestdeal.com' <?php if($this->site == 'fancybestdeal.com'){echo 'selected="selected"';}?>>fancybestdeal.com</option>
	    	    <option value='elmontyouthsoccer.com' <?php if($this->site == 'elmontyouthsoccer.com'){echo 'selected="selected"';}?>>elmontyouthsoccer.com</option>
		        <option value='bestcheapsoccer.com' <?php if($this->site == 'bestcheapsoccer.com'){echo 'selected="selected"';}?>>bestcheapsoccer.com</option>
	    	</select>
        </div>
        <div class="form-group">
            <!--<label for="Site">状态</label>-->
            <select class='form-control' name='statu'>
                <option value='' <?php if($this->statu == ''){echo 'selected="selected"';}?>>选择状态</option>
                <option value='0' <?php if($this->statu == '0'){echo 'selected="selected"';}?>>未分拣,未处理</option>
		        <option value='1' <?php if($this->statu == '1'){echo 'selected="selected"';}?>>分拣中,缺货中</option>
		        <option value='2' <?php if($this->statu == '2'){echo 'selected="selected"';}?>>分拣完,未处理</option>
		        <option value='3' <?php if($this->statu == '3'){echo 'selected="selected"';}?>>分拣完,处理中</option>
		        <option value='4' <?php if($this->statu == '4'){echo 'selected="selected"';}?>>分拣完,处理完</option>
	    	</select>
        </div>
        <div class="form-group">
            <!--<label for="Site">状态</label>-->
            <select class='form-control' name='info_stock'>
		        <option value='sub' <?php if($this->infostock == 'sub'){echo 'selected="selected"';}?>>非退货订单</option>
                <option value='add' <?php if($this->infostock == 'add'){echo 'selected="selected"';}?>>要退货订单</option>
                <!-- <option value='nor' <?php if($this->infostock == 'nor'){echo 'selected="selected"';}?>>未处理退货</option>
                <option value='yesr' <?php if($this->infostock == 'yesr'){echo 'selected="selected"';}?>>已处理退货</option> -->
	    	</select>
        </div>
        <div class="form-group">
            <!--<label for="Site">状态</label>-->
            <select class='form-control' name='is_memo'>
                <option value='' <?php if($this->ismemo == ''){echo 'selected="selected"';}?>>选择备注</option>
                <option value='0' <?php if($this->ismemo == '0'){echo 'selected="selected"';}?>>无</option>
		        <option value='1' <?php if($this->ismemo == '1'){echo 'selected="selected"';}?>>未阅</option>
		        <option value='2' <?php if($this->ismemo == '2'){echo 'selected="selected"';}?>>已阅</option>
	    	</select>
        </div>
        <div class="form-group">
            <label for="date">日期:</label>
            <input class="form-control" type="text" name="starttime" onclick="new Calendar().show(this);" readonly="readonly" value="<?php echo $this->starttime;?>">
	               至<input class="form-control" type="text" name="endtime" onclick="new Calendar().show(this);" readonly="readonly" value="<?php echo $this->endtime;?>">
        </div>
        <button type="submit" class="btn btn-primary">搜索</button>
    </form>
    <div class="table-responsive">
        <table class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th>订单号</th>
                    <th>SKU</th>
                    <th>产品名称</th>
                    <th>尺码和数量</th>
                    <th>网站</th>
                    <th>时间</th>
                    <th>状态</th>
                    <th>备注</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>      
                <?php 
                if ($this->logList){
                	$i=0;
                	$class = 'info';
                    foreach ($this->logList as $v){
                    	if($i>0){
                    		if($v['order_id'] == $this->logList[$i-1]['order_id']){
                    			//$class='info';
                    		}else{
                    			$class = $class=='warning'?'info':'warning';
                    		}
                    	}
                    	$i+=1;
                ?>
                <tr class="<?php echo $class;?> <?php echo $v['order_id']; ?>" data-id="<?php echo $v['order_id']; ?>">
				    <td><?php echo $v['order_id']; ?></td>
                    <td><?php echo $v['sku'];?></td>
                    <td><?php echo $v['title'];?></td>
                    <td>
                        <?php  
                        $info = json_decode($v['info'], true);
                        $vinfo = '';
                        //处理$v['info']可能出现重复的尺码的问题
                        foreach($info as $v1){
                        	$vnum = 0;
                        	foreach ($info as $v2){
                        		if($v1[0] == $v2[0]){
                        			$vnum += $v2[1];
                        		}
                        	}
                        	$flag = true;
                        	foreach ($vinfo as $v3){
                        		if($v1[0] == $v3[0]){
                        			$flag = false;
                        		}
                        	}
                        	if($flag){
                        		$vinfo[] = array($v1[0],$vnum);
                        	}
                        }
                        foreach($vinfo as $_v){
                        	$act = '';
                        	if ($v['info_stock'] == 'add') {
                        		$act = '+';	
                        	} else {
                        		$act = '-';	
                        	}
                        	echo '尺码: ' . $_v[0] . ', 库存: ' . $act . stripslashes($_v[1]) . '<br/>';
                        }
                        ?>
				    </td>
				    <td><?php echo $v['site'];?></td>
				    <td><?php echo $v['add_time']; ?></td>
				    <td class="statu">
				        <?php
				        if($v['info_stock'] == 'add'){
				        	if($v['statu'] == 5){
				        		echo '<span class="label label-default">已处理退货</span>';
				        	}else{
				        		echo '<span class="label label-danger">未处理退货</span>';
				        	}
				        }else{
				        	switch ($v['statu'])
				        	{
				        		case 1:
				        			echo '<span class="label label-danger">分拣中、缺货中</span>';
				        		    break;
				        	    case 2:
				        		    echo '<span class="label label-info">分拣完、未处理</span>';
				        		    break;
				        	    case 3:
				        		    echo '<span class="label label-primary">分拣完、处理中</span>';
				        	    	break;
				            	case 4:
				        	    	echo '<span class="label label-success">分拣完、处理完</span>';
				        	    	break;
				            	default:
				            		echo '<span class="label label-warning">未分拣、未处理</span>';
				        	}
				        }
				        ?>
				    </td>
				    <td class="statu">
				        <?php
				        	switch ($v['is_memo'])
				        	{
				        		case 1:
				        			echo '<span>未阅</span>';
				        		    break;
				        	    case 2:
				        		    echo '<span>已阅</span>';
				        		    break;
				            	default:
				            		echo '<span>无</span>';
				        	}
				        ?>
				    </td>
				    <td>
				        <?php
				        if($v['info_stock'] == 'add'){
				        	if($v['statu'] == 5){
				        		echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'index','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">查看</a>';
				        	}else{
				        		echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'index','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">查看</a>&nbsp;&nbsp;';
				        		echo '<a class="oper" href="javascript:void(0);" onclick="returnOrder('. $v['id'].', this)">处理</a>';
				        	}
				        }else{
				            switch ($v['statu'])
				            {//下面的$this->url属于Zend_View_Helper_Url的方法
				            	case 1:
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'scanexport','order_id' =>$v['order_id'],'site'=>$v['site']),null,true).'">分拣</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'opersort','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">操作|打包</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'omodify','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">修改</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'index','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">查看</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'omemo','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">备注</a>';
				        	    	break;
				            	case 2:
				            		echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'scanexport','order_id' =>$v['order_id'],'site'=>$v['site']),null,true).'">分拣</a>&nbsp;';
				            		echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'opersort','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">操作|打包</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'omodify','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">修改</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'index','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">查看</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'omemo','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">备注</a>';
				            		break;
				            	case 3:
				            		echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'scanexport','order_id' =>$v['order_id'],'site'=>$v['site']),null,true).'">分拣</a>&nbsp;';
				            		echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'opersort','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">打包</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'omodify','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">修改</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'index','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">查看</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'omemo','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">备注</a>';
				            		break;
				            	case 4:
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'omodify','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">修改</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'index','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">查看</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'omemo','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">备注</a>';
				            		break;
				            	default:
				            		echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'scanexport','order_id' =>$v['order_id'],'site'=>$v['site']),null,true).'">分拣</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'omodify','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">修改</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'index','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">查看</a>&nbsp;';
				        	    	echo '<a target="_blank" href="'.$this->url(array('controller'=>'log','action'=>'omemo','oid' =>$v['order_id'],'site'=>$v['site']),null,true).'">备注</a>';
				            }
				        }
				        ?>
				    </td>
			    </tr> 
			    <?php 
                    } 
                }
                ?>
			    <tr>
			        <td colspan="8">
			        <?php
					     echo $this->paginationControl ( $this->paginator, 'Sliding', 'page/pager.phtml', array (
					     	'orderid'=>$this->orderid,
					     	'sku'=>$this->sku,
					     	'site'=>$this->site,
					     	'statu'=>$this->statu,
					     	'ismemo'=>$this->ismemo,
					     	'infostock'=>$this->infostock,
						    'starttime' => $this->starttime,
						    'endtime' => $this->endtime 
				    	) );
				    ?>
			        </td>
			    </tr>
		    </tbody>
        </table>
    </div>
</div>
</div>
<script type="text/javascript">
    function returnOrder(id, obj) {
        if (confirm('确认处理?')) {
            $.ajax({
                type: "get",
                url: "/log/returnorder?id="+id,
                data: {},    
                success: function(data) {
                    switch(data) {	
                        case "1":
                            var id = $(obj).parent().parent().data('id');
                            $("."+id+" .statu").html('<span class="label label-default">已处理退货</span>');
                            $("."+id+" .oper").html('');
                            break;
	        			default:alert('处理失败');
	        		}
	        	}			
	        });
        }
    }
</script>